
class ArticlesController < ApplicationController
  before_filter :auth_login,:except => [:show]
	def new
      not_show_toolbar
	  @images=(params[:imgs].nil?)? []:params[:imgs].split("==");
	  @article = Article.new
	  @article.body = params[:body]||""
	  @article.person_id= current_person.id
	  @article.category_id = 3
	  @article.published = 1
	end
  
	def show
		not_show_toolbar
		@article = Article.find(params[:id])
		@article.view_count = @article.view_count + 1
		@article.save
		respond_to do |wants|
		  wants.html
		  wants.xml { render :xml => @article.to_xml }
		end		
	end
  
	def index
	end
  
	def create
		  params[:article][:category_id]=3 if params[:article][:category_id].blank?
	  params[:article][:published]=0 if params[:article][:published].blank?
		params[:article][:categoryt_id]=0 if params[:article][:categoryt_id].blank?
		params[:article][:tag_id]=0 if params[:article][:tag_id].blank?
		@article = Article.create(params[:article])
#		event_manager= new EventManager(@article.person_id)
#		event_manager.post_article(@article)
		
				e=Event.new
		e.person_id=@article.person_id
		e.event_type=Event::POST
		e.item_id=@article.id
		e.item_title=@article.title
		e.item_content=@article.body[0..254]
		e.save
		

	  
		respond_to do |wants|
		  wants.html { redirect_to cat_article_path(@cat_id,@article.id) }
		  wants.xml  { render :xml => @article.to_xml }
		end		
	end
  
	def update
		@article = Article.find(params[:id])
		@article.update_attributes(params[:article])
		respond_to do |wants|
		  wants.html { redirect_to cat_article_path(@cat_id,@article.id) }
		  wants.xml  { render :xml => @article.to_xml }
		end	
	end
  
	def destroy
		@article = Article.find(params[:id])
		@categ_id = @article.category_id
		@article.destroy
		respond_to do |wants|
		  wants.html { redirect_to :controller=>'home',:cat_id=>@categ_id }
		  wants.xml  { render :nothing => true }
		end		
	end
  
	def edit
		not_show_toolbar
		@article = Article.find(params[:id])
	end
end

